package cdu.sl.service.impl;

import cdu.sl.custom.CustomUserDetails;
import cdu.sl.pojo.dto.ClazzQueryDTO;
import cdu.sl.pojo.vo.ClazzVO;
import cdu.sl.repository.basic.ClazzRepository;
import cdu.sl.service.ClazzService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class ClazzServiceImpl implements ClazzService {

    private final ClazzRepository clazzRepository;

    /**
     * 条件查询班级列表
     * @param condition 查询条件 包含学段和年级
     */
    @Override
    public List<ClazzVO> list(ClazzQueryDTO condition) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        CustomUserDetails customUserDetails = (CustomUserDetails) authentication.getPrincipal();
        return clazzRepository.findClassList(customUserDetails.getUser().getSchoolId(), condition.getStage(), condition.getGrade());
    }




}
